$(function () {
    var informationIcon = $(".informationIcon").text();
    if (informationIcon == "0") {
        $(".informationIcon").css("display", "none");
    } else {
        $(".informationIcon").css("display", "inline-block");
    }
});
//下载App隐藏的二维码部分
$(".download").hover(function () {
    $(".downloadHide").toggle();
});
$(".downloadHide").hover(function () {
    $(".downloadHide").toggle();
});

//登录之后个人信息的下拉菜单部分
$(".myselfPic").hover(function () {
    $(".myselfDownList").toggle();
});
$(".myselfDownList").hover(function () {
    $(".myselfDownList").toggle();
});
//退出用户
$(".loginOut").click(function () {
    $.ajax({
        type: "post",
        url: "/user/loginOut",
        data: {},
        success: function (data) {
            alert(data.msg);
            window.location.href = "/user/sign";
        },
        error: function () {

        }
    });
});
/*评论框的出现*/
$(".speak").click(function () {
    $(".star").toggle(500);
})
$(".say").click(function () {
    $(this).parent().parent().next().toggle(500);
})
$(".speaker").click(function () {
    $(this).next().toggle(500);
})
/*评论问题*/
$(".star-ask").click(function () {
    var myDate = new Date;
    var year = myDate.getFullYear(); //获取当前年
    var mon = myDate.getMonth(); //获取当前月
    var date = myDate.getDate(); //获取当前日
    var h = myDate.getHours();       //获取当前小时数(0-23)
    var m = myDate.getMinutes();     //获取当前分钟数(0-59)
    var qId = $(".qId").val();
    var qAdress = $("#star").val();
    var picture = $(".picture").val();
    var uname = $(".uname").val();
    if ($("#star").val() == "") {
        confirm("不能发表空的评论")
    } else {
        $.ajax({
            url: "/question/commentQuestion",
            type: "post",
            data: {
                qId: qId,
                cAddress: qAdress,
            },
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    var Str = `<div class="reply">
                <div class="head-img">
                    <img src="` + picture + `"/>
                </div>
                <div class="reply-content">
                    <h4>` + uname + `</h4>
                    <span>` + year + '-' + mon + '-' + date + '' + h + ':' + m + `</span>
                    <p>` + qAdress + `</p>
                    <div class="speak">
                        <div style="float: left;width:83%;height:10px;"></div>
                        <div style="float: left;width: 17%;">
                            <span class="say">回复</span>
                        </div>
                    </div>
                    <div class="again" style="display: none;margin-bottom: 10px;">
                        <textarea placeholder="回复" class="word"></textarea>
                        <button class="again-reply">评论</button>
                    </div>
                </div>
            </div>`;
                    $(".reply").prepend(Str);
                    $(".star").hide()
                    alert(data.msg);
                }
            }
        })
    }
})

/*回复别人的评论前的名字*/
$(".say").click(function () {
    var people = $(this).parent().parent().parent().find("h4").text();
    var star1 = $(this).parent().parent().next();
    var input = star1.find("textarea");
    input.attr('placeholder', '回复' + people);
})

/*回复评论*/
$(".again-reply").click(function () {
    var dad = $(this).parent().parent();
    var quser = dad.find("h4").text();
    var we = $(this);
    var myDate = new Date;
    var year = myDate.getFullYear(); //获取当前年
    var mon = myDate.getMonth(); //获取当前月
    var date = myDate.getDate(); //获取当前日
    var h = myDate.getHours();  //获取当前小时数(0-23)
    var m = myDate.getMinutes();//获取当前分钟数(0-59)
    var uname = $(".uname").val();//当前用户
    var name = $(".name").val();//提出问题的用户
    var user = $(".user").val();//当前用户
    var id = $(".id").val();
    var div = $(this).parent().parent();
    var again = div.find("div:eq(3)");
    var text = again.find("textarea").val();
    if (text == "") {
        confirm("回复内容不能为空");
    } else {
        $.ajax({
            url: "/reply/replyComment",
            type: "post",
            data: {
                rUId: uname,
                cId: id,
                tUId: name,
                rAddress: text,
            },
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    var str = `<div class="reply2" style="display: none;">
                            <div>
                            <div>
                            <span>` + user + `</span>回复
                            <span>` + quser + `</span>
                            </div>
                            <p>` + text + `</p>
                            <span>` + year + '-' + mon + '-' + date + '' + h + ':' + m + `</span>
                            <span class="speaker">回复</span>
                            <div class="again" style="display: none;margin-bottom: 10px;">
                            <textarea placeholder="回复" class="word"></textarea>
                            <button class="again-reply">评论</button>
                            </div>
                            </div>
                            </div>`;
                    we.parent().next().append(str);
                    console.log(we.parent().next());
                    $(".speaker").unbind();
                    $(".speaker").click(function(){
                        $(this).next().toggle(500);
                    })
                    $(".again").hide(500);
                    alert(data.msg);
                }
            }
        })
    }
})

/*查看更多*/
$(".look").click(function () {
    var bdiv = $(this).parent().parent().parent();
    var reply2 = bdiv.children(".reply2");
    reply2.toggle(500);
})
/*隐藏*/
var  count=$(".count");
for (var i=0;i<count.length;i++){
    if ($(count[i]).text()==0){
       $(count[i]).prev().hide();
       $(count[i]).hide();
        $(count[i]).next().hide();
       console.log($(count[i]).prev())
    }
}